__all__ = [
    "LCG",
]

#a, c, m = 214013, 2531011, 4294967296
#a, c, m = 1103515245, 12345, 4294967296
a, c, m = 1664525, 1013904223, 4294967296
#a, c, m = 22695477, 1, 4294967296
#a, c, m = 134775813, 1, 4294967296

class LCG:
    """线性同余生成器"""

    def __init__(self, seed=0):
        self.seed = seed
        self.a, self.c, self.m = a, c, m
        self.count = 0

    def __iadd__(self, c):
        self.count = 0
        self.c = c
        return self

    def __imul__(self, a):
        self.count = 0
        self.a = a
        return self

    def __imod__(self, m):
        self.count = 0
        self.m = m
        return self

    def __mul__(self, x):
        return [+self for _ in range(x)]

    def __invert__(self):
        return (self.seed * self.a + self.c) % self.m

    def __neg__(self):
        return ~ self / self.m

    def __pos__(self):
        self.count += 1
        self.seed = ~self
        return -self

    def __call__(self, item):
        o = list(item)
        return o[int(+self*len(o))]

    def __getitem__(self, f):
        if type(f) == type(slice(0)):
            if f.step == None:
                self.count, self.seed = 0, f.start
                self*f.stop if f.stop != None else None
                return self
            else:
                def iterin():
                    for _ in range(f.step):
                        yield +self * (f.stop - f.start) + f.start
                return iterin()
        elif type(f) == type(0):
            def iterin(item):
                o = list(item)
                l = len(o)
                return (o[int(+self*l)] for _ in range(f))
            return iterin
        else:
            return self


if __name__ == '__main__':
    a = LCG(14562)
    ll = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in a[10](a*3):
        print(i)
